package main

import "fmt"

type Worker struct {
}

func (t Worker) Speak() {
	fmt.Println("工人")
}

type Teacher struct {
}

func (t Teacher) Speak() {
	fmt.Println("老师")
}

type Student struct {
}

func (t Student) Speak() {
	fmt.Println("学生")
}

type SpeakerTypes interface {
	Teacher | Student
	Speak()
}

type Speaker[T SpeakerTypes] struct {
	Internal T
}

// 规定只有实现了SpeakerTypes接口并且只能是Teacher | Student两个类型才能调用
func (s Speaker[T]) Speak() {
	s.Internal.Speak()
}

// 带有参数集合的接口只能作为泛型参数，不能用于函数接收者，以下会报错
//func (s SpeakerType) SpeakA() {
//	s.Speak()
//}

func main() {
	speaker := Speaker[Student]{}
	speaker.Speak()
}
